package cn.lcsjsxy.yxz.day.IO;

import java.io.*;

//字符流
public class Characterstream {
    public static void main(String[] args) {

        //文件复制~缓冲~字符串

        // TODO 源文件
        File srcFile = new File("D:\\yang\\idea\\day10\\data\\word.txt");
        // TODO 数据目的地文件对象(自动生成)
        File destFile = new File("D:\\yang\\idea\\day10\\data\\word.txt.copy");

        //文件输入流(管道对象)
        FileInputStream in = null;
        //文件输出流(管道对象)
        FileOutputStream out = null;

        try {
            in = new FileInputStream(srcFile);
            out = new FileOutputStream(destFile);

            //打开阀门,流转数据(输入)
            int data = -1;

            StringBuilder ss = new StringBuilder();

            while ((data = in.read()) != -1){
//                System.out.println(data + 1);
//                out.write(data + 1);
                ss.append((char) data);
            }

            ss.append("123");
            System.out.println(ss);
            // 可以讲字符串转换成字节数组，再讲数组中的每一个字节写入到文件中

            // Unicode编码
            // byte => -128 ~ 127
            // asc => 0 ~ 127

        }catch (IOException e){
            throw new RuntimeException(e);
        }finally {
            if (in != null){
                try {
                    in.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            if (out != null){
                try {
                    out.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }






    }

}
